/**
 * hnjz.com Inc.
 * Copyright (c) 2004-2013 All Rights Reserved.
 */
package com.hnjz.common.security;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hnjz.common.YnEnum;
import com.hnjz.common.security.domain.Oper;

/**
 * 获取当前功能所具有的操作
 * 
 * @author wumi
 * @version $Id: OperateUtil.java, v 0.1 Jan 14, 2013 11:28:38 AM wumi Exp $
 */
public class OperateUtil {

    /**日志*/
    private static final Log log = LogFactory.getLog(OperateUtil.class);

    /**
     * 获取当前功能所具有的操作
     * 
     * @param id 记录id
     * @return 当前功能所具有的操作
     */
    public static String getOperate(String id) {
        List<Oper> opers = AppCtxStrategy.getOp();
        if (null == opers) {
            return "";
        }
        StringBuilder str = new StringBuilder();
        String temp = " <a onclick='function' id='poid' >operate</a>  ";
        for (Oper ele : opers) {
            if (StringUtils.equals(YnEnum.N.getCode(), ele.getFashion())
                || StringUtils.isBlank(ele.getFunction())) {
                continue;
            }
            String op = temp.replace("function", ele.getFunction());
            op = op.replace("poid", id);
            op = op.replace("operate", ele.getName());
            str.append(op);
        }
        if (log.isDebugEnabled()) {
            log.debug("str:" + str);
        }
        return str.toString();
    }
}
